﻿@model Nop.Web.Models.Customer.CustomerInfoModel
@using Nop.Web.Framework;
@{
    Layout = "~/Views/Shared/_ColumnsTwo.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Account").Text);
}
@section left
{
    @Html.Partial("MyAccountNavigation", Model.NavigationModel, new ViewDataDictionary())
}
@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script type="text/javascript">
     $(function() {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                var statesProgress = $("#states-loading-progress");
                statesProgress.show();
                $.ajax({
                    cache:false,
                    type: "GET",
                    url: "@(Url.Action("GetStatesByCountryId", "Country"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        statesProgress.hide();
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to retrieve states.');
                        statesProgress.hide();
                    }  
                });
            });
        });
</script>
}
<div class="account-page">
    <div class="page-title">
        <h1>@T("Account.MyAccount") - @T("Account.CustomerInfo")</h1>
    </div>
    <div class="clear">
    </div>
    <div class="body">
        <div class="section-body">
            @using (Html.BeginForm())
            {
                @Html.AntiForgeryToken()
                <div class="customer-info-box">
                    <div class="message-error">
                        @Html.ValidationSummary(true)
                    </div>
                    <div class="clear">
                    </div>
                    <div class="section-title">
                        @T("Account.YourPersonalDetails")
                    </div>
                    <div class="clear">
                    </div>
                    <div class="section-body">
                        <table class="table-container">
                            <tbody>
                                @if (Model.GenderEnabled)
                                {
                                    <tr class="row">
                                        <td class="item-name">
                                            @Html.LabelFor(model => model.Gender):
                                        </td>
                                        <td class="item-value">
                                            @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "Gender_Male" })
                                            <label class="forcheckbox" for="Gender_Male">@T("Account.Fields.Gender.Male")</label>
                                            @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "Gender_Female" })
                                            <label class="forcheckbox" for="Gender_Female">@T("Account.Fields.Gender.Female")</label>
                                        </td>
                                    </tr>
                                }
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.FirstName):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.FirstName)
                                        @Html.ValidationMessageFor(model => model.FirstName)
                                    </td>
                                </tr>
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.LastName):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.LastName)
                                        @Html.ValidationMessageFor(model => model.LastName)
                                    </td>
                                </tr>
                                @if (Model.DateOfBirthEnabled)
                                {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.DateOfBirthDay):
                                    </td>
                                    <td class="item-value">
                                        @Html.DatePickerDropDowns(Html.FieldNameFor(x => x.DateOfBirthDay),
                                        Html.FieldNameFor(x => x.DateOfBirthMonth),
                                        Html.FieldNameFor(x => x.DateOfBirthYear),
                                        DateTime.Now.Year - 110,
                                        DateTime.Now.Year,
                                        Model.DateOfBirthDay,
                                        Model.DateOfBirthMonth,
                                        Model.DateOfBirthYear)
                                        @Html.ValidationMessageFor(model => model.DateOfBirthDay)
                                        @Html.ValidationMessageFor(model => model.DateOfBirthMonth)
                                        @Html.ValidationMessageFor(model => model.DateOfBirthYear)
                                    </td>
                                </tr>
                                }
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.Email):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.Email)
                                        @Html.ValidationMessageFor(model => model.Email)
                                    </td>
                                </tr>
                                @if (Model.UsernamesEnabled)
                                {
                                    if (Model.AllowUsersToChangeUsernames)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.Username):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.Username)
                                                @Html.ValidationMessageFor(model => model.Username)
                                            </td>
                                        </tr>
                                        if (Model.CheckUsernameAvailabilityEnabled)
                                        {
                                            <tr class="row">
                                                <td class="item-name">
                                                </td>
                                                <td class="item-value">
                                                    @Html.Partial("_CheckUsernameAvailability")
                                                </td>
                                            </tr>
                                        }
                                    }
                                    else
                                    {
                                    <tr class="row">
                                        <td class="item-name">
                                            @Html.LabelFor(model => model.Username):
                                        </td>
                                        <td class="item-value">
                                            @Model.Username
                                        </td>
                                    </tr>
                                    }
                                }
                                @*Associated external authentication records*@
                                @if (Model.AssociatedExternalAuthRecords.Count > 0)
                                {
                                    <tr class="row">
                                        <td class="item-name">
                                            @Html.LabelFor(model => model.AssociatedExternalAuthRecords):
                                        </td>
                                        <td class="item-value">
                                            <table class="data-table">
                                                <col />
                                                <col />
                                                <col />
                                                <thead>
                                                    <tr>
                                                        <th class="a-center">
                                                            @T("Account.AssociatedExternalAuth.AuthMethodName")
                                                        </th>
                                                        <th class="a-center">
                                                            @T("Account.AssociatedExternalAuth.Email")
                                                        </th>
                                                        <th class="a-center">
                                                            @T("Account.AssociatedExternalAuth.ExternalIdentifier")
                                                        </th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    @foreach (var item in Model.AssociatedExternalAuthRecords)
                                                    {
                                                        <tr>
                                                            <td class="a-left">
                                                                @item.AuthMethodName
                                                            </td>
                                                            <td class="a-left">
                                                                @item.Email
                                                            </td>
                                                            <td class="a-left">
                                                                @item.ExternalIdentifier
                                                            </td>
                                                        </tr>
                                                    }
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                    <div class="clear">
                    </div>
                    @if (Model.CompanyEnabled || Model.DisplayVatNumber)
                    {
                        <div class="section-title">
                            @T("Account.CompanyDetails")
                        </div>
                        <div class="clear">
                        </div>
                        <div class="section-body">
                            <table class="table-container">
                                <tbody>
                                    @if (Model.CompanyEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.Company):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.Company)
                                                @Html.ValidationMessageFor(model => model.Company)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.DisplayVatNumber)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.VatNumber):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.VatNumber)&nbsp;&nbsp;&nbsp;@Model.VatNumberStatusNote
                                            </td>
                                        </tr>
                                        <tr class="row">
                                            <td colspan="2">
                                                <i>@T("Account.Fields.VatNumber.Note")</i>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                        <div class="clear">
                        </div>
                    }
                    @if (Model.StreetAddressEnabled ||
                        Model.StreetAddress2Enabled ||
                        Model.ZipPostalCodeEnabled ||
                        Model.CityEnabled ||
                        Model.CountryEnabled)
                    {
                        <div class="section-title">
                            @T("Account.YourAddress")
                        </div>
                        <div class="clear">
                        </div>
                        <div class="section-body">
                            <table class="table-container">
                                <tbody>
                                    @if (Model.StreetAddressEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.StreetAddress):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.StreetAddress)
                                                @Html.ValidationMessageFor(model => model.StreetAddress)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.StreetAddress2Enabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.StreetAddress2):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.StreetAddress2)
                                                @Html.ValidationMessageFor(model => model.StreetAddress2)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.ZipPostalCodeEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.ZipPostalCode):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.ZipPostalCode)
                                                @Html.ValidationMessageFor(model => model.ZipPostalCode)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.CityEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.City):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.City)
                                                @Html.ValidationMessageFor(model => model.City)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.CountryEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.CountryId):
                                            </td>
                                            <td class="item-value">
                                                @Html.DropDownList("CountryId", Model.AvailableCountries)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.CountryEnabled && Model.StateProvinceEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.StateProvinceId):
                                            </td>
                                            <td class="item-value">
                                                @Html.DropDownList("StateProvinceId", Model.AvailableStates)
                                                <span id="states-loading-progress" style="display: none;">@T("Common.Wait...")
                                                    <img src='@Url.Content("~/Content/Images/ajax_loader_small.gif")' alt="@T("Common.Wait...")" />
                                                </span>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                        <div class="clear">
                        </div>
                    }
                    @if (Model.PhoneEnabled || Model.FaxEnabled)
                    {
                        <div class="section-title">
                            @T("Account.YourContactInformation")
                        </div>
                        <div class="clear">
                        </div>
                        <div class="section-body">
                            <table class="table-container">
                                <tbody>
                                    @if (Model.PhoneEnabled)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.Phone):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.Phone)
                                                @Html.ValidationMessageFor(model => model.Phone)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.FaxEnabled)
                                    {                                    
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.Fax):
                                            </td>
                                            <td class="item-value">
                                                @Html.EditorFor(model => model.Fax)
                                                @Html.ValidationMessageFor(model => model.Fax)
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                        <div class="clear">
                        </div>
                    }
                    @if (Model.NewsletterEnabled)
                    {
                        <div class="section-title">
                            @T("Account.Options")
                        </div>
                        <div class="clear">
                        </div>
                        <div class="section-body">
                            <table class="table-container">
                                <tbody>
                                    <tr class="row">
                                        <td class="item-name">
                                            @Html.LabelFor(model => model.Newsletter):
                                        </td>
                                        <td class="item-value">
                                            @Html.EditorFor(model => model.Newsletter)
                                            @Html.ValidationMessageFor(model => model.Newsletter)
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="clear">
                        </div>
                    }
                    @if (Model.AllowCustomersToSetTimeZone || Model.SignatureEnabled)
                    {
                        <div class="section-title">
                            @T("Account.Preferences")
                        </div>
                        <div class="clear">
                        </div>
                        <div class="section-body">
                            <table class="table-container">
                                <tbody>
                                    @if (Model.AllowCustomersToSetTimeZone)
                                    {
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.TimeZoneId):
                                            </td>
                                            <td class="item-value">
                                                @Html.DropDownList("TimeZoneId", Model.AvailableTimeZones)
                                                @Html.ValidationMessageFor(model => model.TimeZoneId)
                                            </td>
                                        </tr>
                                    }
                                    @if (Model.SignatureEnabled)
                                    {                                    
                                        <tr class="row">
                                            <td class="item-name">
                                                @Html.LabelFor(model => model.Signature):
                                            </td>
                                            <td class="item-value">
                                                @Html.TextAreaFor(model => model.Signature, new { @class = "accountsignaturetext" })
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        </div>
                        <div class="clear">
                        </div>
                    }
                    <div class="buttons">
                        <input type="submit" id="save-info-button" value="@T("Common.Save")" name="save-info-button" class="savecustomerinfobutton" />
                    </div>
                </div>
            }
        </div>
    </div>
</div>
